<!-- 医生体检核验 -->
<template>
	<view class="wrapper">
		
		<view class="content-wrapper">
			<p style="font-size: 1.1rem; color: #000;">
				我的核销数据
			</p>
			<p>今年体检订单量: {{getcheckupdata.order_year}}</p>
			<p>今年核销量: {{getcheckupdata.used_year}}</p>
			<p>当月订单量: {{getcheckupdata.order_current_month}}</p>
			<p>当月核销量: {{getcheckupdata.used_current_month}}</p>
		</view>
		
		<u-button type="success" text="扫码核验" @click="scVerify()"></u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				getcheckupdata: {
					order_year: 0,
					used_year:  0,
					order_current_month: 0,
					used_current_month: 0
				},
				scResult: ''
			}
		},
		onLoad(option) {
			this.api_getcheckupdata()
		},
		methods: {
			scVerify() {
				uni.scanCode({
					onlyFromCamera: true,
					success: (res) => {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						this.scResult = res.result
						this.api_verifyorder(this.scResult)
					}
				});
			},
			api_getcheckupdata() {
				let openid = uni.getStorageSync('openid')
				this.$app._post_form("entry/wxapp/apicheckup.getcheckupdata", {
					openid: openid
				}, (res) => {
					console.log(res)
					this.getcheckupdata = res[0]
				})
			},
			api_verifyorder(scResult) {
				let scResultObj = JSON.parse(scResult)
				let openid = uni.getStorageSync('openid')
				this.$app._post_form("entry/wxapp/apicheckup.verifyorder", {
					openid: openid,
					id: scResultObj.id,
					copenid: scResultObj.copenid
				}, (res) => {
					console.log(res)
					if (res.status == 1) {
						uni.showToast({
							title: '核验成功',
							icon: 'success',
							duration: 5000
						})
						// this.api_getcheckupdata()
					}else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 5000
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrapper {
		padding: 10px;
		box-sizing: border-box;
		color: #757575;
		
		.content-wrapper {
			border-radius: 6px;
			border: 1px solid #e3e3e3;
			padding: 10px;
			line-height: 25px;
			background-color: #f5f5f5;
			font-size: .9rem;
			color: #757575;
			margin-bottom: 15px;
		}
	}
</style>